//
//  MLAEateryHomeVC.m
//  MagicLampApp
//
//  Created by Zheng on 2018/12/30.
//  Copyright © 2018 zheng.magic.lamp.app. All rights reserved.
//

#import "MLAEateryHomeVC.h"
#import "MLAEateryManageVC.h"
#import "MLAEateryHomeModel.h"
#import "MLAShopOrderMainVC.h"
#import "MLAShopFoodManageVC.h"

@interface MLAEateryHomeVC ()

@property (nonatomic, strong) MLAEateryHomeModel *model;


@end

@implementation MLAEateryHomeVC {
    UIImageView *shopLogoImgv;
    UILabel *shopNameLbl;
    UILabel *shopStateLbl;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configTitle:@"供餐方"];
    
    if (![_openType isEqualToString:@"1"]) {
        self.titlesArr = @[@"我的订单",@"菜品管理",@"店铺管理"];
        [self.tableView reloadData];
        
        [self configShopInfoView];
    } else {
        [self configNotOpenView];
    }
    
    [self loadData];
}

- (void)loadData {
    
    
    [MLAHttpManage postHostType:MLAHttpHostType_Diancan api:kShopShopDetails params:nil success:^(id  _Nonnull response, NSString * _Nonnull msg) {
        self.model = [MLAEateryHomeModel mj_objectWithKeyValues:response[@"lists"][0]];
        [shopLogoImgv sd_setImageWithURL:[NSURL URLWithString:self.model.shop_logo]];
        shopNameLbl.text = self.model.shop_name;
        shopStateLbl.text = self.model.status.integerValue==1? @"店铺状态：开": @"店铺状态：关";
    } failure:^{
        
    }];
}

#pragma mark - TableviewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [super tableView:tableView didSelectRowAtIndexPath:indexPath];
    
    if (indexPath.row == 0) {
        CX_Log(@"我的订单");
        MLAShopOrderMainVC *somVC = [[MLAShopOrderMainVC alloc] init];
        [self.navigationController pushViewController:somVC animated:YES];
    } else if (indexPath.row == 1) {
        CX_Log(@"菜品管理");
        MLAShopFoodManageVC *sfmVC = [[MLAShopFoodManageVC alloc] init];
        [self.navigationController pushViewController:sfmVC animated:YES];
    } else if (indexPath.row == 2) {
        CX_Log(@"店铺管理");
        MLAEateryManageVC *emVC = [[MLAEateryManageVC alloc] init];
        emVC.model = _model;
        [self.navigationController pushViewController:emVC animated:YES];
    }
}

#pragma mark - 设置店铺信息视图
- (void)configShopInfoView {
    
    UIView *tableHeaderView = [[UIView alloc] init];
    tableHeaderView.frame = CGRectMake(0, 0, CX_GetScreenWidth(), 120);
    
    shopLogoImgv = [[UIImageView alloc] init];
    [tableHeaderView addSubview:shopLogoImgv];
    [shopLogoImgv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(75);
        make.left.mas_equalTo(15);
        make.centerY.equalTo(tableHeaderView);
    }];
    
    shopNameLbl = [[UILabel alloc] init];
    shopNameLbl.font = CX_GetNormalFont(18);
    shopNameLbl.textColor = CX_GetColorTitle();
    [tableHeaderView addSubview:shopNameLbl];
    [shopNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(shopLogoImgv.mas_right).offset(20);
        make.top.equalTo(shopLogoImgv);
        make.right.mas_equalTo(-15);
    }];
    
    shopStateLbl = [[UILabel alloc] init];
    shopStateLbl.font = CX_GetNormalFont(12);
    shopStateLbl.textColor = CX_GetColorHex(0x999999, 1);
    [tableHeaderView addSubview:shopStateLbl];
    [shopStateLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(shopLogoImgv.mas_right).offset(20);
        make.top.equalTo(shopNameLbl.mas_bottom).offset(20);
        make.width.mas_equalTo(100);
    }];
    
    UISwitch *shopSwitch = [[UISwitch alloc] init];
    shopSwitch.hidden = YES;
    shopSwitch.tintColor = CX_GetColorBlue();
    shopSwitch.onTintColor = CX_GetColorBlue();
    [tableHeaderView addSubview:shopSwitch];
    [shopSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.bottom.equalTo(shopLogoImgv).offset(-4);
    }];
    
    
    self.tableView.tableHeaderView = tableHeaderView;
    [tableHeaderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(0);
        make.width.mas_equalTo(CX_GetScreenWidth()).priorityHigh();
        make.height.mas_equalTo(120);
    }];

}

#pragma mark - 未开店视图
- (void)configNotOpenView {
    UIButton *shopIconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [shopIconBtn setImage:[UIImage imageNamed:@"food_shop_icon"] forState:UIControlStateNormal];
    shopIconBtn.userInteractionEnabled = NO;
    shopIconBtn.backgroundColor = CX_GetColorBlue();
    shopIconBtn.layer.cornerRadius = 22;
    shopIconBtn.layer.masksToBounds = YES;
    [self.view addSubview:shopIconBtn];
    [shopIconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(30);
        make.width.height.mas_equalTo(44);
        make.centerX.equalTo(self.view);
    }];
    
    UILabel *titleLbl = [[UILabel alloc] init];
    titleLbl.text = @"您还没有开店,快去开店吧";
    titleLbl.font = CX_GetBoldFont(14);
    titleLbl.textColor = CX_GetColorTitle();
    [self.view addSubview:titleLbl];
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(shopIconBtn.mas_bottom).offset(20);
        make.centerX.equalTo(self.view);
    }];
    
    UIButton *openApplyBtn = [self getCommitButtonWithTitle:@"申请开店"];
    [openApplyBtn addTarget:self action:@selector(openApplyBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:openApplyBtn];
    [openApplyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLbl.mas_bottom).offset(40);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(40);
    }];
    
}

#pragma mark - Actions
- (void)openApplyBtnAction {
#pragma mark 申请开店
    CX_Log(@"申请开店");
}






@end
